/**
 * 输入一个链表，反转链表后，输出新链表的表头。
 */
public class Solution24 {
    public ListNode ReverseList(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode result = null;

        ListNode before = null;
        ListNode current = head;
        ListNode temp;
        while (current != null) {
            temp = current.next;
            current.next = before;
            if (temp == null) {
                result = current;
            }
            before = current;
            current = temp;
        }
        return result;
    }
}
